@echo off
set PATH=%PATH%;%CD%\tools\7z;%CD%\tools\ar;%CD%\tools\Enigma Virtual Box
set EXE_PATH=%CD%\release\nw.exe
set ICO_PATH=%CD%\favicon.ico
set NWJS_PATH=%CD%\tools\nwjs-v0.12.0-win-ia32
set NWEXE_PATH=%NWJS_PATH%\nw.exe
set NWZIP_PATH=%CD%\release\app.nw
set SPLICE_PATH=%CD%\release\editor.md.app.exe
set APP_EXE=%CD%\release\nw.exe

if not exist release md release

set NWZIP_FILE=%CD%\editor.md
set NWZIP_FILE=%NWZIP_FILE% %CD%\emoji-cheat-sheet.com
set NWZIP_FILE=%NWZIP_FILE% %CD%\katex
set NWZIP_FILE=%NWZIP_FILE% %CD%\to-markdown
set NWZIP_FILE=%NWZIP_FILE% %CD%\twemoji
set NWZIP_FILE=%NWZIP_FILE% %CD%\Zebra_Dialog
set NWZIP_FILE=%NWZIP_FILE% %CD%\favicon.ico
set NWZIP_FILE=%NWZIP_FILE% %CD%\LICENSE
set NWZIP_FILE=%NWZIP_FILE% %CD%\main.html
set NWZIP_FILE=%NWZIP_FILE% %CD%\package.json

echo =========================================================================
echo Package Application to ZIP file
7z a -r -tzip %NWZIP_PATH% %NWZIP_FILE%

echo =========================================================================
echo Update application icon.
copy %NWEXE_PATH% %APP_EXE%
Resourcer -op:upd -src:%APP_EXE% -type:14 -name:IDR_MAINFRAME -file:%ICO_PATH%

echo =========================================================================
echo Splice nw.exe and application zip file.
copy /b %APP_EXE%+%NWZIP_PATH% %SPLICE_PATH%

echo =========================================================================
echo Delete application zip file.
del %NWZIP_PATH%

echo =========================================================================
echo Copy nwjs runtime
xcopy %NWJS_PATH% %CD%\release /e /y
del %CD%\release\nw.exe
del %CD%\release\*.tmp

echo =========================================================================
echo Package all files to alone executeable file.
enigmavbconsole editor.md.app.evb

echo =========================================================================
echo Delete all the intermediate files.
rd /q /s release

echo =========================================================================
echo The release of the executable file compression.
7z a -t7z -mx9 -r editor.md.app.boxed.1.4.0.7z editor.md.app.exe

echo =========================================================================
echo Packing success.
pause

